﻿Imports System
Imports NUnit.Framework
Imports ValidationFramework

Namespace ParameterValidationManagerExamples
    Public Class BasicDelegateExample
#Region "Example"
        Public Class Person
            Private ReadOnly checkAgeDelegate As Action(Of Integer)

            Public Sub New()
                checkAgeDelegate = AddressOf CheckAge
            End Sub

            Public Sub CheckAge(<CompareIntRule(5, CompareOperator.LessThan)> ByVal age As Integer)
                ParameterValidationManager.ThrowException(Me, checkAgeDelegate, age)

                'business code goes here.
            End Sub
        End Class

        <TestFixture()> _
        Public Class ExampleUsage
            <Test(), ExpectedException(GetType(ArgumentException))> _
            Public Sub RunInvalidData()
                Dim person = New Person()
                person.CheckAge(7)
            End Sub


            <Test()> _
            Public Sub RunValidData()
                Dim person = New Person()
                person.CheckAge(2)
            End Sub
        End Class
#End Region
    End Class
End Namespace